package com.lgywin.runserver.server;

import com.google.protobuf.InvalidProtocolBufferException;
import com.lgywin.runserver.entity.generate.NetCode;
import com.lgywin.runserver.protobuf.NetProto;
import com.lgywin.runserver.service.UserService;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class NetProHandleToService {

    @Resource
    private UserService userService;

    public void run(ChannelHandlerContext ctx, NetProto netProto) throws InvalidProtocolBufferException {
        int protoCode = netProto.getProtoCode();
        switch (protoCode) {
            case NetCode.HEARTBEATPROTO: {
                ctx.writeAndFlush(netProto);
            }
            break;

            default:
                log.error("未知协议号 protoCode is error! protoCode=>" + protoCode);
                throw new RuntimeException("未知协议号 protoCode is error! protoCode=>" + protoCode);
        }
    }
}
